package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zbl.zblproject.erp.entity.ErpFinanceLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/12/11
 */
@Repository
public interface ErpFinanceLogMapper  extends BaseMapper<ErpFinanceLog> {

    @Select("SELECT * FROM zbl_finance_log WHERE order_sn = #{orderSn}")
    ErpFinanceLog selectLogByOrderSn(@Param("orderSn") String orderSn);

    @Update("UPDATE zbl_finance_log SET status = #{status} WHERE order_sn = #{orderSn}")
    int updateLogStatusByOrderSn(@Param("orderSn") String orderSn, @Param("status") int status);

    @Select("SELECT status FROM zbl_finance_log WHERE order_sn = #{orderSn}")
    Integer selectStatusByOrderSn(@Param("orderSn") String orderSn);

    @Select("SELECT SUM(paid) FROM zbl_finance_log WHERE status = 2 AND store_name = #{supplierName} AND  checktime BETWEEN #{start} AND #{end} ")
    BigDecimal selectAllPriceBySupplierNameAndTime(@Param("supplierName") String supplierName,
                                                   @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
}
